home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-24 | 9.3 KB | 381 lines | [TEXT/MPS ] |
- // Copyright © 1994-95 by Apple Computer, Inc. All rights reserved.
- // UShapes.cp
-
- #ifndef __UPICTSHAPE__
- #include "UPictShape.h"
- #endif
-
- // MacApp
-
- #ifndef __UDIALOG__
- #include <UDialog.h>
- #endif
-
- #ifndef __UFILE__
- #include <UFile.h>
- #endif
-
- #ifndef __UMEMORY__
- #include <UMemory.h>
- #endif
-
- #ifndef __USTREAM__
- #include <UStream.h>
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- #ifndef __UVIEW__
- #include <UView.h>
- #endif
-
- // Toolbox
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- // DrawShapes
-
- #ifndef __PATTERNMENU__
- #include "PatternMenu.h"
- #endif
-
- #ifndef __UDRAWSHAPES__
- #include "UDrawShapes.h"
- #endif
-
- #ifndef __USHAPEVIEW__
- #include "UShapeView.h"
- #endif
-
- //----------------------------------------------------------------------------------------
-
- const Boolean kUseOutlineFonts = true;
-
- const short kPictureInset = 4;
-
- const ResNumber kDefaultPictureID = 1000;
-
-
- //========================================================================================
- // CLASS TDocPicture
- //========================================================================================
- #undef Inherited
- #define Inherited TPicture
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TDocPicture, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TDocPicture constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TDocPicture::TDocPicture()
- {
- }
-
-
- //----------------------------------------------------------------------------------------
- // TDocPicture::ReleasePicture:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TDocPicture::ReleasePicture() // override
- {
- if ((fRsrcID != kNoResource) && (fDataHandle != NULL))
- HPurge((Handle)fDataHandle);
-
- fRsrcID = kNoResource;
- fDataHandle = NULL;
- }
-
-
- //========================================================================================
- // CLASS TPictShape
- //========================================================================================
- #undef Inherited
- #define Inherited TShape
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TPictShape, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TPictShape Constructor
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- TPictShape::TPictShape()
- {
- fPicture = NULL;
- fPictData = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::IPictShape
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TPictShape::IPictShape(const CRect& itsExtent, short itsID)
- {
- IShape(itsExtent, itsID);
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::DoInitialState
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TPictShape::DoInitialState(TShapeView* itsView)
- {
- Inherited::DoInitialState(itsView);
-
- CreatePicture(itsView);
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::CreatePicture
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TPictShape::CreatePicture(TView* itsView)
- {
- if (!fPicture)
- {
- VPoint loc(fLocation);
- VPoint size(fSize);
- VPoint inset(kPictureInset, kPictureInset);
- loc += inset;
- size -= inset;
- size -= inset;
-
- fPicture = new TDocPicture;
- fPicture->IPicture(itsView, loc, size, sizeFixed, sizeFixed, kDefaultPictureID);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::SetPictureFrame
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TPictShape::SetPictureFrame()
- {
- if (fPicture)
- {
- VPoint loc(fLocation);
- VPoint size(fSize);
- VPoint inset(kPictureInset, kPictureInset);
- loc += inset;
- size -= inset;
- size -= inset;
- VRect newFrame(loc, loc + size);
- fPicture->SetFrame(newFrame, kInvalidate);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::Clone
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
-
- TObject* TPictShape::Clone() // Override
- {
- TPictShape* bozo = (TPictShape*) Inherited::Clone();
- FailNIL(bozo);
-
- bozo->fPicture = NULL;
- bozo->fPictData = NULL;
-
- if (fPictData)
- {
- Size pictSize = GetHandleSize((Handle) fPictData);
- PicHandle pictData = (PicHandle) NewPermHandle(pictSize);
- FailNIL(pictData);
- MABlockMove(*fPictData, *pictData, pictSize);
- bozo->fPictData = pictData;
- }
-
- return bozo;
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::Free
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
-
- void TPictShape::Free() // Override
- {
- fPicture = NULL; // (TDocPicture*) FreeIfObject(fPicture);
- fPictData = NULL; // (PicHandle) DisposeIfHandle((Handle) fPictData);
-
- Inherited::Free();
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::ReadFrom
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
-
- void TPictShape::ReadFrom(TStream* aStream) // Override
- {
- Inherited::ReadFrom(aStream);
-
- PicHandle pictData = (PicHandle) aStream->ReadHandle();
- SetPicture(pictData);
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::WriteTo
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- void TPictShape::WriteTo(TStream* aStream) // Override
- {
- Inherited::WriteTo(aStream);
-
- aStream->WriteHandle((Handle) fPictData);
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::SetPicture
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- void TPictShape::SetPicture(PicHandle pictData)
- {
- if (fPictData != pictData)
- {
- fPictData = (PicHandle) DisposeIfHandle((Handle) fPictData);
- fPictData = pictData;
- }
-
- if (!fPicture)
- CreatePicture(NULL);
-
- if (fPicture && (GetHandleSize((Handle) fPictData) > 0))
- fPicture->SetPicture(fPictData, kDontRedraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::BeInView
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TPictShape::BeInView(TShapeView* itsView) // Override
- {
- // Inherited::BeInView(itsView);
-
- if (!fPicture)
- CreatePicture(itsView);
- else
- itsView->AddSubView(fPicture);
-
- if (fPictData)
- SetPicture(fPictData);
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::Draw
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TPictShape::Draw() // Override
- {
- CRect extent;
- GetFrame(extent);
-
- PenNormal();
- if (qNeedsColorQD || gConfiguration.hasColorQD)
- {
- // Get the color of the menu item representing the shape's color
- RGBForeColor(fColor);
- DrawInsides(extent);
- ForeColor(blackColor);
- }
- else
- DrawInsides(extent);
-
- if (!fPicture)
- {
- CStr255 s("\pP");
-
- TextFont(geneva);
- TextFace(normal);
- TextSize(9);
- TextMode(srcOr);
-
- short x = (extent.left + extent.right) / 2;
- short w = StringWidth(s) / 2;
- CRect r(x - w, extent.bottom - 14, x + w, extent.bottom - 4);
- EraseRect(r);
- MADrawString(s, r, teCenter, kUseOutlineFonts);
- }
-
- DrawOutline();
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::DrawInsides
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TPictShape::DrawInsides(const CRect& extent)
- {
- CRect r(extent);
-
- r.bottom = extent.top + kPictureInset;
- FillRect(r, &gPat[fPattern]);
- r.bottom = extent.bottom;
-
- r.right = extent.left + kPictureInset;
- FillRect(r, &gPat[fPattern]);
- r.right = extent.right;
-
- r.left = extent.right - kPictureInset;
- FillRect(r, &gPat[fPattern]);
- r.left = extent.left;
-
- r.top = extent.bottom - kPictureInset;
- FillRect(r, &gPat[fPattern]);
- r.top = extent.top;
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::DrawOutline
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TPictShape::DrawOutline()
- {
- PenSize(1, 1);
- CRect extent;
- GetFrame(extent);
- FrameRect(extent);
- }
-
- //----------------------------------------------------------------------------------------
- // TPictShape::SetFrame
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- void TPictShape::SetFrame(const CRect& extentRect) // override
- {
- CRect oldFrame;
- GetFrame(oldFrame);
- if (oldFrame != extentRect)
- {
- Inherited::SetFrame(extentRect);
- if (fPicture)
- SetPictureFrame();
- }
- }
-
-